/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-07-19 00:06:00
 * @LastEditors: GaoYiNuo 1534815804@qq.com
 * @LastEditTime: 2022-07-24 22:02:29
 * @FilePath: \project\src\store\modules\action.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '../../utils/request'
import { Dispatch } from 'redux'
import {
    ArticleItem,//文章
    TITLEITEM,//
    LISTITEM,//mockjs数据列表的约束
    COMMENTLISTITEM,//评论列表的约束
    dataItem,//获取数据接口的元素约束
    USERSTATE//登陆成功约束数据
} from '../../type/router.d'

import '../../api/about/comment'//关于页面的mock

// 留言板数据
export const getData = () => {
    return async (dispatch: Dispatch) => {
        let res = await request.get('/api/article')
        dispatch({
            type: 'GETDATA',
            payload: res.data.data[0]
        })
    }
}
// 留言板分页
export const PagData = (data: any) => {
    return {
        type: 'PAGDATA',
        payload: data
    }
}

// 获取文章列表数据
export const GetArticleList = (can: ArticleItem[]) => ({
    type: 'GETARTICLELIST',
    payload: can,
})

// tab切换
export const changeIndex = (can: string) => ({
    type: 'CHANGE_INDEX',
    payload: can,
})

// 详情页数据
export const GetXiangList = (can: object) => ({
    type: 'GETXIANGLIST',
    payload: can,
})

// 获取轮播图数据
export const GetLbtList = (can: ArticleItem[]) => ({
    type: 'GETLBTLIST',
    payload: can,
})


// 轮播图详情
export const getXiangLb = (can: object) => ({
    type: 'GETXIANGLB',
    payload: can,
})

// 点赞
export const addZan = (can: object) => ({
    type: 'ADDZAN',
    payload: can,
})

// 阅读
export const addLook = (can: object) => ({
    type: 'ADDLOOK',
    payload: can,
})

//获取标题内容数据
export const getTitileAction = (arr: TITLEITEM[]) => {
    return {
        type: "GETTITLEDATA",
        payload: arr
    }
}

//获取详情数据
export const getDetailAction = (obj: TITLEITEM) => {
    return {
        type: "GETDETAILDATA",
        payload: obj
    }
}
//获取归档页面数据
export const getactDataAction = (arr: any) => {
    return {
        type: "GETACTDATA_ACTION",
        payload: arr
    }
}

//获取详情数据
export const getActDetailAction = (obj: any) => {
    return {
        type: "GETACTDETAILDATA",
        payload: obj
    }
}
//=== 关于页面action方法
// 下边数据跳转详情 getDetail
export const getDetail = (payload: number) => ({
    type: 'GET_DETAIL',
    payload,
})
// 评论列表的 切换评论当前页码 changeComPage
export const changeComPage = (payload: number) => ({
    type: 'CHANGE_COM_PAGE',
    payload,
})

// import { get_comment_list } from '../api/index.js';//获取数据的请求接口
// 评论列表 异步获取 
export const getCommentList = () => {
    return (dispatch: Dispatch) => {
        return request.get('/getCommentList').then((res: any) => {
            return dispatch({
                type: 'GET_COMMENT_LIST',
                payload: res.data.commentList,
            })
        })
    }
}

//数据列表 截取的数据
export const getList = (payload: dataItem[]) => ({
    type: 'GET_LIST',
    payload,
})
// 下边列表总数据 getListAll
export const getListAll = (payload: dataItem[]) => ({
    type: 'GET_LIST_ALL',
    payload,
}) 

//保存登陆成功数据
export const storageUserState=(obj:USERSTATE)=>({
    type:"STORAGE_USER_STATE",
    payload:obj
})
